$(document).ready(function() {
    
    // START GALLERIA
    startGalleria();
    
    // PRODUCT LIST ACCORDION
    productList();
    $('.mod-list-green > a').click();
    
    // PAGINATION
    pagination();
    
    // ADD CLASS TO ADMIN CONTAINER
    var pathname = $(location).attr('href');
    var $container = $('#gbl-container');
    if (pathname.indexOf('admin') >= 0) {
        $container.addClass('gbl-container-admin');
    } else {
        $('#gbl-asd').show();
    }
    

});

// GALLERIA
function startGalleria() {
	var options = {
		width              : 550,
        height             : 390,
        showInfo           : true,
        transition         : 'fade',
	    imageCrop          : true,
	    pauseOnInteraction : true,
	    thumbnails         : false
	}
	
	Galleria.loadTheme('/js/libs/galleria/themes/nutrisimo/galleria.nutrisimo.js');
	
	$('#mod-gallery').galleria(options);
}

// PRODUCT LIST ACCORDION
function productList() {
    
    var $openUL;                         // Active List
    var $links = $('div.mod-list > a');  // Collection of anchors
    var $lists = $('div.mod-list > ul'); // Collection of lists
    
    // Apply Accordion funcionality to all links
    $links.each(function() {
        
        var $this = $(this);                  // Current selected anchor
        var $thisUL = $(this).siblings('ul'); // Sibling list of current anchor
        
        $this.click(function(e) {
            e.preventDefault();
            $links.removeClass('mod-list-link-active')
                .filter($this).addClass('mod-list-link-active');
            
            if($thisUL == $openUL) {
                
                // Hide list if it's active when clicking
                $thisUL.slideToggle();
                $links.removeClass('mod-list-link-active');
                $openUL = '';
            
            } else {
                
                // Hide all list and show the one clicked
                $lists.each(function() {
                    $(this).slideUp();
                })
                    .filter($thisUL).slideToggle();
                
                $openUL = $thisUL;
            
            }
        });
    });
}

// PAGINATION
function pagination() {
    $('.mod-pages').jqPagination({
		page_string : 'Pagina {current_page} de {max_page}',
		link_string	: '/?page={page_number}',
		max_page	: 40,
		paged		: function(page) {
			// do something with the page variable
			console.log(page);
		}
	});
}